//
//  WebServiceApi.h
//  fa
//
//  Created by lj on 16/1/27.
//  Copyright © 2016年 lj. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "CZLErrMsg.h"
#import <UIKit/UIKit.h>
//创建单例
#ifndef SHARED_SERVICE
#define SHARED_SERVICE(ServiceName) \
+(instancetype)sharedInstance \
{ \
static ServiceName * sharedInstance; \
static dispatch_once_t onceToken; \
dispatch_once(&onceToken, ^{ \
sharedInstance = [[ServiceName alloc] init]; \
}); \
return sharedInstance; \
}
#endif
// 服务器地址（内网）
//#define SERVER @"http://192.168.13.200:8080/WebAPI/"
//公网服务器
//#define SERVER @"http://183.221.3.245:8090/WebAPI/"

//#define SERVER @"http://192.168.20.187:8080/WebAPI/"

#define CODE_SUCCESS            200
#define CODE_TOKEN_INVALID      400

typedef void(^FSRequestSuccessBlock)(NSInteger code, NSString *message, id content);
typedef void(^FSRequestFailBlock)(NSInteger code, NSString *message, id content);

@interface FSRequest : NSObject

@property (nonatomic, assign) BOOL isNetWork;

+ (instancetype)sharedInstance;

///拼接路径
+ (NSString *)urlWithServer:(NSString*)server andPath:(NSString *)path;

- (void)getRequestWithPath:(NSString *)pathString
                    params:(NSMutableDictionary *)params
                   headers:(NSMutableDictionary *)headers
               resultClass:(Class)resultClass
                   success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock;

- (void)postRequestWithPath:(NSString *)pathString
                     params:(NSMutableDictionary *)params
                    headers:(NSMutableDictionary *)headers
                resultClass:(Class)resultClass
                    success:(FSRequestSuccessBlock)successBlock
                       fail:(FSRequestFailBlock)failBlock;

- (void)putRequestWithPath:(NSString *)pathString
                    params:(NSMutableDictionary *)params
                   headers:(NSMutableDictionary *)headers
               resultClass:(Class)resultClass
                   success:(FSRequestSuccessBlock)successBlock
                      fail:(FSRequestFailBlock)failBlock;

- (void)deleteRequestWithPath:(NSString *)pathString
                       params:(NSMutableDictionary *)params
                      headers:(NSMutableDictionary *)headers
                  resultClass:(Class)resultClass
                      success:(FSRequestSuccessBlock)successBlock
                         fail:(FSRequestFailBlock)failBlock;

#pragma mark - 上传图片的接口
- (void)uploadImageWithPath:(NSString *)pathString
                     params:(NSMutableDictionary *)params
                     images:(NSArray *)images
                  imageName:(NSString *)imageName
                resultClass:(Class)resultClass
                    success:(FSRequestSuccessBlock)successBlock
                       fail:(FSRequestFailBlock)failBlock;

- (void)requestWithMethod:(NSString *)method withPath:(NSString *)path withParams:(NSDictionary *)params withBodyParams:(NSDictionary *)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock;

- (void)bodyPostRequestWithPath:(NSString *)path withBodyParams:(id)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock;

- (void)bodyGetRequestWithMethod:(NSString *)method withPath:(NSString *)path withBodyParams:(NSDictionary *)bodyParams withHeaders:(NSDictionary *)headers withResultClass:(Class)resultClass withSuccess:(FSRequestSuccessBlock)successBlock withFail:(FSRequestFailBlock)failBlock;

- (void)cancelRequest;

@end
